package cn.good.yan.w1;

import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;


/**
 * 2 Web 操作的Rest 请求
 * @author shengren.yan
 * @create 2023-10-01
 */
@RestController
@RequestMapping("/test2")
public class Con2 {

    @GetMapping("/get/{id}")
    public String getCar(
            // 路径变量
            @PathVariable("id") Integer id,
            // 获取请求头
            @RequestHeader("User-Agent") String userAgent,
            @RequestHeader Map<String,String> header,  // 全部的消息头信息
            // 获取请求参数
            @RequestParam("age") Integer age,
            @RequestParam(value = "type",defaultValue = "view") String type,
            @RequestParam("inters") List<String> inters // xxx?age=8&arrs=n1&arrs=n2&arrs=n3
            // 获取cookie
            // @CookieValue("_ga") String _ga,
            // 得到Cookie对象  @CookieValue("cookie") Cookie cookie
    ){
        System.out.println(id);
        return id.toString();
    }

    // @RequestBody 请求体信息
    @PostMapping("/save")
    public Map<String, Object> postMethod(@RequestBody String content){
        Map<String,Object> map = new HashMap<>();
        map.put("content",content);
        return map;
    }

    @GetMapping("/get")
    public String get(){
        return "get请求";
    }

    @PostMapping("/post")
    public String post(){
        return "post";
    }

    @DeleteMapping("/delete")
    public String delete(){
        return "delete";
    }

    @PutMapping("put")
    public String put(){
        return "put";
    }

}
